package com.wtb.javatool.action;

import com.alibaba.fastjson.JSONArray;
import com.fy.wetoband.tool.Tool;
import com.fy.wetoband.utils.RequestUtil;
import com.wtb.javatool.common.PageBean;
import com.wtb.javatool.common.R;
import com.wtb.javatool.dto.*;
import com.wtb.javatool.entity.*;
import com.wtb.javatool.service.*;
import com.wtb.javatool.vo.UserVo;
import io.swagger.annotations.*;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Scope;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE;


@Api(tags = {"项目式教学工具相关接口"})
@Scope(SCOPE_PROTOTYPE) //务必使用多实例模式
@ComponentScan("com.wtb.javatool")
public class ProjectTeaching extends Tool {

    @Autowired
    private ProjectService projectService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private CourseService courseService;
    @Autowired
    private UserService userService;
    @Autowired
    private AssignmentService assignmentService;
    @Autowired
    private AttachmentService attachmentService;
    @Autowired
    private LineService lineService;
    @Autowired
    private SubmissionService submissionService;
    @Autowired
    private EvaluationService evaluationService;
    @Autowired
    private ProjectClassService projectClassService;
    @Autowired
    private TeamService teamService;

    @Action
    @ApiOperation(value = "创建单个任务", httpMethod = "POST", notes = "创建单个任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", dataType = "long", value = "项目ID", required = true),
            @ApiImplicitParam(name = "taskName", dataType = "string", value = "任务名称", required = true),
            @ApiImplicitParam(name = "taskType", dataType = "integer", value = "任务类型", required = true),
            @ApiImplicitParam(name = "createTime", dataType = "date", value = "创建时间", required = true),
            @ApiImplicitParam(name = "creatorId", dataType = "long", value = "创建人ID", required = true),
            @ApiImplicitParam(name = "taskDescription", dataType = "string", value = "任务描述"),
            @ApiImplicitParam(name = "courseId", dataType = "long", value = "课程ID"),
            @ApiImplicitParam(name = "deliverables", dataType = "Array", value = "附件"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "创建任务成功")
    })
    public R<Long> createTask(HttpServletRequest request) {
        //参数获取
        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        String taskName = RequestUtil.getStringParameter(request, "taskName");
        Integer taskType = RequestUtil.getIntegerParameter(request, "taskType");
        Date createTime = RequestUtil.getDateParameter(request, "createTime");
        Long creatorId = RequestUtil.getLongParameter(request, "creatorId");
        String taskDescription = RequestUtil.getStringParameter(request, "taskDescription");
        Long courseId = RequestUtil.getLongParameter(request, "courseId");
        //生成对象
        Task task = new Task();
        task.setTaskName(taskName);
        task.setProjectId(projectId);
        task.setCreatorId(creatorId);
        task.setTaskDescription(taskDescription);
        task.setCreateTime(createTime);
        task.setTaskType(taskType);
        task.setCourseId(courseId);
        //调用服务层
        taskService.createTask(task);
        return R.success(task.getTaskId(), "创建成功");
    }

    @Action
    @ApiOperation(value = "创建项目", httpMethod = "POST", notes = "添加项目信息与相关成员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectName", dataType = "string", value = "项目名称", required = true),
            @ApiImplicitParam(name = "projectDescription", dataType = "string", value = "项目描述", required = true),
            @ApiImplicitParam(name = "projectType", dataType = "integer", value = "项目类型", required = true),
            @ApiImplicitParam(name = "creatorId", dataType = "long", value = "创建人ID", required = true),
            @ApiImplicitParam(name = "leaders", dataType = "list", value = "项目负责人ID列表", required = true),
            @ApiImplicitParam(name = "endTime", dataType = "date", value = "项目期限"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "创建项目成功")
    })
    public R<String> createProject(HttpServletRequest request) {
        List<Long> leaders = RequestUtil.getLongJsonArrayParameter(request, "leaders");
        Project project = new Project();
        project.setProjectName(RequestUtil.getStringParameter(request, "projectName"));
        project.setProjectDescription(RequestUtil.getStringParameter(request, "projectDescription"));
        Integer projectType = RequestUtil.getIntegerParameter(request, "projectType");
        project.setProjectType(projectType);
        project.setCreatorId(RequestUtil.getLongParameter(request, "creatorId"));
        project.setCreateTime(RequestUtil.getDateParameter(request, "createTime"));
        project.setEndTime(RequestUtil.getDateParameter(request, "endTime"));
        projectService.createProject(project, leaders, projectType);

        return R.success("创建项目成功");
    }


    @Action
    @ApiOperation(value = "查询用户", httpMethod = "GET", notes = "根据不同属性查询用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", dataType = "Long", value = "用户ID"),
            @ApiImplicitParam(name = "userName", dataType = "String", value = "用户名"),
            @ApiImplicitParam(name = "phone", dataType = "String", value = "手机号"),
            @ApiImplicitParam(name = "projectType", dataType = "Integer", value = "项目类型"),
            @ApiImplicitParam(name = "userType", dataType = "Integer", value = "用户类型"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<List<User>> findUser(HttpServletRequest request) {
        Long userId = RequestUtil.getLongParameter(request, "userId");
        String userName = RequestUtil.getStringParameter(request, "userName");
        String phone = RequestUtil.getStringParameter(request, "phone");
        Integer projectType = RequestUtil.getIntegerParameter(request, "projectType");
        Integer userType = RequestUtil.getIntegerParameter(request, "userType");
        List<User> users = userService.findUser(userId, userName, phone, projectType, userType);

        return R.success(users, "查询成功");
    }

    @Action
    @ApiOperation(value = "查询项目", httpMethod = "POST", notes = "根据用户ID，项目名称（可选）等来查找相关项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", dataType = "Long", value = "用户ID", required = true),
            @ApiImplicitParam(name = "projectName", dataType = "String", value = "项目名称"),
            @ApiImplicitParam(name = "projectType", dataType = "Integer", value = "项目类型"),
            @ApiImplicitParam(name = "projectStatus", dataType = "Integer", value = "项目状态"),
            @ApiImplicitParam(name = "projectDate", dataType = "List<String>", value = "日期范围"),
            @ApiImplicitParam(name = "currentPage", dataType = "Integer", value = "当前页数", required = true),
            @ApiImplicitParam(name = "pageSize", dataType = "Integer", value = "每页总数", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<PageBean<Project>> findProjects(HttpServletRequest request) {
        // 获取 projectDate 参数

        //参数获取
        Long userId = RequestUtil.getLongParameter(request, "userId");
        String projectName = RequestUtil.getStringParameter(request, "projectName");
        Integer projectType = RequestUtil.getIntegerParameter(request, "projectType");
        Integer projectStatus = RequestUtil.getIntegerParameter(request, "projectStatus");
        List<Long> projectDate = RequestUtil.getLongJsonArrayParameter(request, "projectDate");
        Integer currentPage = RequestUtil.getIntegerParameter(request, "currentPage");
        Integer pageSize = RequestUtil.getIntegerParameter(request, "pageSize");
        PageBean<Project> pageBean = projectService.findProjectsByUserId(userId, projectName, projectType, projectStatus, projectDate, currentPage, pageSize);
        return R.success(pageBean, "查询成功");
    }
//日期记录2025/3/12

    @Action
    @ApiOperation(value = "查询项目基本信息", httpMethod = "GET", notes = "根据项目ID获取项目基本信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", dataType = "long", value = "项目ID", required = true),
            @ApiImplicitParam(name = "projectType", dataType = "int", value = "项目类型", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<ProjectDto> findProjectByProjectId(HttpServletRequest request) {

        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        Integer projectType = RequestUtil.getIntegerParameter(request, "projectType");

        ProjectDto projectDto = projectService.findProjectByProjectId(projectId, projectType);
        return R.success(projectDto, "查询成功");
    }

    @Action
    @ApiOperation(value = "查询普通项目的所有成员", httpMethod = "GET", notes = "根据项目ID，项目名称（可选）、项目时间范围（可选获取项目所有成员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", dataType = "Long", value = "项目ID", required = true),
            @ApiImplicitParam(name = "userName", dataType = "String", value = "用户名")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<List<UserDto>> findProjectMemberByProjectId(HttpServletRequest request) {
        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        String userName = RequestUtil.getStringParameter(request, "userName");
        return R.success(projectService.findProjectMemberByProjectId(projectId, userName));
    }

    @Action
    @ApiOperation(value = "查询课程项目的下的小组及其成员", httpMethod = "GET", notes = "根据项目ID，项目名称（可选）、项目时间范围（可选获取项目所有成员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", dataType = "Long", value = "项目ID"),
            @ApiImplicitParam(name = "courseId", dataType = "Long", value = "课程ID"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<List<TeamDto>> findProjectTeamsAndMembersByProjectId(HttpServletRequest request) {
        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        Long courseId = RequestUtil.getLongParameter(request,"courseId");
        return R.success(projectService.findProjectTeamsAndMembersByProjectId(projectId,courseId));
    }

    @Action
    @ApiOperation(value = "查询项目所有任务", httpMethod = "GET",
            notes = "根据项目ID，任务名称（可选）、任务类型（可选）、所属课程ID（可选）、创建人（可选）或承担者（可选）获取项目所有相关任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", dataType = "long", value = "项目ID", required = true),
            @ApiImplicitParam(name = "taskName", dataType = "string", value = "任务名称"),
            @ApiImplicitParam(name = "taskType", dataType = "integer", value = "任务类型"),
            @ApiImplicitParam(name = "courseId", dataType = "long", value = "所属课程ID"),
            @ApiImplicitParam(name = "creatorId", dataType = "long", value = "创建人ID"),
            @ApiImplicitParam(name = "userId", dataType = "long", value = "或承担者"),
            @ApiImplicitParam(name = "currentPage", dataType = "integer", value = "当前页数", required = true),
            @ApiImplicitParam(name = "pageSize", dataType = "integer", value = "每页条数", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<PageBean<TaskDto>> findTasksByProjectId(HttpServletRequest request) {
        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        String taskName = RequestUtil.getStringParameter(request, "taskName");
        Integer taskType = RequestUtil.getIntegerParameter(request, "taskType");
        Long courseId = RequestUtil.getLongParameter(request, "courseId");
        Long creatorId = RequestUtil.getLongParameter(request, "creatorId");
        Long userId = RequestUtil.getLongParameter(request, "userId");
        Integer currentPage = RequestUtil.getIntegerParameter(request, "currentPage");
        Integer pageSize = RequestUtil.getIntegerParameter(request, "pageSize");
        PageBean<TaskDto> pageBean = new PageBean<>();
        if (userId != null) {
            pageBean.setRows(taskService.findMyTasksByProjectIdAndUserId(projectId, taskName, taskType, courseId, userId, currentPage, pageSize));
            pageBean.setTotalCount(taskService.countMyTasksByProjectIdAndUserId(projectId, taskName, taskType, courseId, userId));
            return R.success(pageBean, "查询成功");
        } else {
            pageBean.setRows(taskService.findTasksByProjectId(projectId, taskName, taskType, courseId, creatorId, currentPage, pageSize));
            pageBean.setTotalCount(taskService.countTasksByProjectId(projectId, taskName, taskType, courseId, creatorId));
        }

        return R.success(pageBean, "查询成功");
    }

    @Action
    @ApiOperation(value = "更新项目的成员", httpMethod = "POST",
            notes = "根据前端传输的成员列表，增删改相对应项目下的成员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", dataType = "long", value = "项目ID", required = true),
            @ApiImplicitParam(name = "userList", dataType = "string", value = "用户列表字符串", required = true),

    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "更新成功")
    })
    public R<String> upsertDeleteUsers(HttpServletRequest request) {
        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        String list = RequestUtil.getStringParameter(request, "userList");
        List<UserDto> userDtoList = JSONArray.parseArray(list, UserDto.class);

        projectService.upsertDeleteUsers(projectId, userDtoList);
        return R.success("更新成功");
    }

    @Action
    @ApiOperation(value = "更新项目信息", httpMethod = "POST",
            notes = "根据前端传输的项目信息，修改数据库中对应的项目实体")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", dataType = "long", value = "项目ID"),
            @ApiImplicitParam(name = "projectName", dataType = "string", value = "项目名称"),
            @ApiImplicitParam(name = "projectDescription", dataType = "string", value = "项目描述"),
            @ApiImplicitParam(name = "projectStatus", dataType = "integer", value = "项目状态"),
            @ApiImplicitParam(name = "startTime", dataType = "date", value = "开始时间"),
            @ApiImplicitParam(name = "endTime", dataType = "date", value = "结束时间"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "更新成功")
    })
    public R<String> updateProject(HttpServletRequest request) {
        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        String projectName = RequestUtil.getStringParameter(request, "projectName");
        String projectDescription = RequestUtil.getStringParameter(request, "projectDescription");
        Integer projectStatus = RequestUtil.getIntegerParameter(request, "projectStatus");
        Date startTime = RequestUtil.getDateParameter(request, "startTime");
        Date endTime = RequestUtil.getDateParameter(request, "endTime");
        Project project = new Project();
        project.setProjectId(projectId);
        project.setProjectName(projectName);
        project.setProjectDescription(projectDescription);
        project.setProjectStatus(projectStatus);
        project.setStartTime(startTime);
        project.setEndTime(endTime);
        projectService.updateProject(project);

        return R.success("更新成功");
    }

    @Action
    @ApiOperation(value = "查询课程", httpMethod = "GET", notes = "根据不同属性查询课程列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId", dataType = "Long", value = "课程号"),
            @ApiImplicitParam(name = "courseName", dataType = "string", value = "课程名"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<List<Course>> findCourse(HttpServletRequest request) {
        Long courseId = RequestUtil.getLongParameter(request, "courseId");
        String courseName = RequestUtil.getStringParameter(request, "courseName");
        List<Course> courseList = courseService.findCourse(courseId, courseName);
        return R.success(courseList, "查询成功");
    }

    @Action
    @ApiOperation(value = "更新项目关联的课程", httpMethod = "POST",
            notes = "根据前端传输的课程列表，增删相对应项目关联的课程")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", dataType = "long", value = "项目ID", required = true),
            @ApiImplicitParam(name = "courseList", dataType = "string", value = "课程列表字符串", required = true),

    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "更新成功")
    })
    public R<String> upsertDeleteCourses(HttpServletRequest request) {
        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        String list = RequestUtil.getStringParameter(request, "courseList");
        List<Course> courseList = JSONArray.parseArray(list, Course.class);
        projectService.upsertDeleteCourses(projectId, courseList);
        return R.success("更新成功");
    }

    @Action
    @ApiOperation(value = "查看项目首页中，任务分配及完成情况", httpMethod = "GET",
            notes = "初步查看各任务的分配，完成等数量并返回给前端展示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", dataType = "long", value = "项目ID", required = true),
            @ApiImplicitParam(name = "Integer", dataType = "Integer", value = "评价类型", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<AssignmentDto> findTaskAssignmentNumber(HttpServletRequest request) {
        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        Integer evaluationType = RequestUtil.getIntegerParameter(request, "evaluationType");
        AssignmentDto assignmentDto = taskService.findTaskAssignmentNumber(projectId, evaluationType);
        return R.success(assignmentDto, "查询成功");
    }

    @Action
    @ApiOperation(value = "查看任务详情", httpMethod = "GET",
            notes = "根据任务ID，返回任务详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", dataType = "long", value = "任务ID", required = true),
            @ApiImplicitParam(name = "projectType", dataType = "Integer", value = "项目类型", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<TaskDto> findTaskByTaskId(HttpServletRequest request) {
        Long taskId = RequestUtil.getLongParameter(request, "taskId");
        Integer projectType = RequestUtil.getIntegerParameter(request, "projectType");
        TaskDto taskDto = taskService.findTaskByTaskId(taskId, projectType);
        return R.success(taskDto, "查询成功");
    }

    @Action
    @ApiOperation(value = "为单个任务添加附件", httpMethod = "POST",
            notes = "根据任务ID，返回任务详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", dataType = "long", value = "任务ID", required = true),
            @ApiImplicitParam(name = "file", dataType = "file", value = "文件", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "添加成功")
    })
    public R<String> upLoadTaskAttachment(HttpServletRequest request) throws Exception {
        Long taskId = RequestUtil.getLongParameter(request, "taskId");
        Long creatorId = RequestUtil.getLongParameter(request, "creatorId");
        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
        List<FileItem> items = upload.parseRequest(request);
        attachmentService.upLoadTaskAttachment(taskId, creatorId, items);
        return R.success("添加成功");
    }

    @Action
    @ApiOperation(value = "删除附件", httpMethod = "POST",
            notes = "删除某个附件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "attachmentId", dataType = "long", value = "附件ID", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "删除成功")
    })
    public R<String> deleteAttachmentByAttachmentId(HttpServletRequest request) {
        Long attachmentId = RequestUtil.getLongParameter(request, "attachmentId");
        String attachmentUrl = RequestUtil.getStringParameter(request, "attachmentUrl");
        attachmentService.deleteAttachmentByAttachmentId(attachmentId, attachmentUrl);
        return R.success("", "删除成功");
    }

    @Action
    @ApiOperation(value = "查询某个任务的所有附件", httpMethod = "GET",
            notes = "根据任务ID，返回任务的所有附件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", dataType = "long", value = "任务ID", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<List<Attachment>> findAttachmentsByTaskId(HttpServletRequest request) {
        Long taskId = RequestUtil.getLongParameter(request, "taskId");
        List<Attachment> attachmentList = attachmentService.findAttachmentsByTaskId(taskId);

        return R.success(attachmentList, "查询成功");
    }

    @Action
    @ApiOperation(value = "更新任务名称", httpMethod = "POST",
            notes = "更新任务名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", dataType = "long", value = "任务ID", required = true),
            @ApiImplicitParam(name = "taskName", dataType = "string", value = "任务名称", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<String> updateTaskName(HttpServletRequest request) {
        Long taskId = RequestUtil.getLongParameter(request, "taskId");
        String taskName = RequestUtil.getStringParameter(request, "taskName");
        Task task = new Task();
        task.setTaskId(taskId);
        task.setTaskName(taskName);
        taskService.updateTaskName(task);
        return R.success("更新成功", "更新成功");
    }

    @Action
    @ApiOperation(value = "更新任务描述", httpMethod = "POST",
            notes = "更新任务描述")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", dataType = "long", value = "任务ID", required = true),
            @ApiImplicitParam(name = "taskDescription", dataType = "string", value = "任务描述")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<String> updateTaskDescription(HttpServletRequest request) {
        Long taskId = RequestUtil.getLongParameter(request, "taskId");
        String taskDescription = RequestUtil.getStringParameter(request, "taskDescription");
        Task task = new Task();
        task.setTaskId(taskId);
        task.setTaskDescription(taskDescription);
        taskService.updateTaskDescription(task);
        return R.success("更新成功", "更新成功");
    }

    @Action
    @ApiOperation(value = "更新任务类型", httpMethod = "POST",
            notes = "更新任务类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", dataType = "long", value = "任务ID", required = true),
            @ApiImplicitParam(name = "taskType", dataType = "integer", value = "任务类型", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<String> updateTaskType(HttpServletRequest request) {
        Long taskId = RequestUtil.getLongParameter(request, "taskId");
        Integer taskType = RequestUtil.getIntegerParameter(request, "taskType");
        Task task = new Task();
        task.setTaskId(taskId);
        task.setTaskType(taskType);
        taskService.updateTaskType(task);
        return R.success("更新成功", "更新成功");
    }

    @Action
    @ApiOperation(value = "更新任务所属课程", httpMethod = "POST",
            notes = "更新任务所属课程")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", dataType = "long", value = "任务ID", required = true),
            @ApiImplicitParam(name = "courseId", dataType = "long", value = "课程ID", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<String> updateTaskCourse(HttpServletRequest request) {
        Long taskId = RequestUtil.getLongParameter(request, "taskId");
        Long courseId = RequestUtil.getLongParameter(request, "courseId");
        Task task = new Task();
        task.setTaskId(taskId);
        task.setCourseId(courseId);
        taskService.updateTaskCourse(task);
        return R.success("更新成功", "更新成功");
    }

    @Action
    @ApiOperation(value = "普通项目新建任务分配记录和任务承担者", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userIdList", dataType = "list", value = "用户ID列表", required = true),
            @ApiImplicitParam(name = "taskId", dataType = "long", value = "任务ID", required = true),
            @ApiImplicitParam(name = "teamId", dataType = "long", value = "小组ID"),
            @ApiImplicitParam(name = "createTime", dataType = "date", value = "创建时间", required = true),
            @ApiImplicitParam(name = "endTime", dataType = "date", value = "截止时间", required = true),
            @ApiImplicitParam(name = "creatorId", dataType = "long", value = "创建者", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "分配成功")
    })
    public R<String> addAssignmentAndUndertaker(HttpServletRequest request) {
        Long taskId = RequestUtil.getLongParameter(request, "taskId");
        Long creatorId = RequestUtil.getLongParameter(request, "creatorId");
        Long teamId = RequestUtil.getLongParameter(request, "teamId");
        List<Long> userIdList = RequestUtil.getLongJsonArrayParameter(request, "userIdList");
        Date createTime = RequestUtil.getDateParameter(request, "createTime");
        Date endTime = RequestUtil.getDateParameter(request, "endTime");
        Assignment assignment = new Assignment();
        assignment.setTaskId(taskId);
        assignment.setTeamId(teamId);
        assignment.setCreatorId(creatorId);
        assignment.setCreateTime(createTime);
        assignment.setEndTime(endTime);
        assignmentService.addAssignmentAndUndertaker(assignment, userIdList);
        return R.success("分配成功", "分配成功");
    }

    @Action
    @ApiOperation(value = "查询某个任务的所有分配记录（不包括状态值为4（被删除）的记录，）", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", dataType = "Long", value = "任务ID", required = true),
            @ApiImplicitParam(name = "projectType", dataType = "Integer", value = "项目类型", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<List<AssignmentDto>> findAssignmentsByTaskId(HttpServletRequest request) {
        Long taskId = RequestUtil.getLongParameter(request, "taskId");
        Integer projectType = RequestUtil.getIntegerParameter(request, "projectType");
        List<AssignmentDto> assignmentDtoList = assignmentService.findAssignmentsByTaskId(taskId, projectType);
        return R.success(assignmentDtoList, "查询成功");
    }

    @Action
    @ApiOperation(value = "根据分配记录ID列表删除对应分配记录(将状态值改为4）", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "assignmentIdList", dataType = "list", value = "分配记录ID列表", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "删除成功"),
            @ApiResponse(code = 409, message = "删除失败，该记录已被分配到产线")
    })
    public R<String> deleteAssignmentByAssignmentId(HttpServletRequest request) {
        List<Long> assignmentIdList = RequestUtil.getLongJsonArrayParameter(request, "assignmentIdList");
        if (lineService.findLineAssignmentByAssignmentIds(assignmentIdList) > 0) {
            return R.error("删除失败，该记录已被分配到产线", 409);
        } else {
            assignmentService.deleteAssignmentByAssignmentId(assignmentIdList);
            return R.success("删除成功");
        }

    }

    @Action
    @ApiOperation(value = "更新单个分配记录的截至日期、承担小组", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "assignmentId", dataType = "Long", value = "分配记录ID", required = true),
            @ApiImplicitParam(name = "endTime", dataType = "Date", value = "截止日期"),
            @ApiImplicitParam(name = "teamId", dataType = "Long", value = "承担小组id"),
            @ApiImplicitParam(name = "userIds", dataType = "List<Long>", value = "承担人员id列表"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "更新成功")
    })
    public R<String> updateAssignmentEndTimeAndMember(HttpServletRequest request) {
        Long assignmentId = RequestUtil.getLongParameter(request, "assignmentId");
        Date endTime = RequestUtil.getDateParameter(request, "endTime");
        Long teamId = RequestUtil.getLongParameter(request, "teamId");
        List<Long> userIds = RequestUtil.getLongJsonArrayParameter(request, "userIds");
        Assignment assignment = new Assignment();
        assignment.setAssignmentId(assignmentId);
        assignment.setEndTime(endTime);
        assignment.setTeamId(teamId);
        assignmentService.updateAssignmentEndTimeAndTeamByAssignmentId(assignment);
        assignmentService.upsertDeleteAssignmentUndertakers(assignmentId, userIds);
        return R.success("更新成功", "更新成功");
    }

    @Action
    @ApiOperation(value = "更新多个分配记录的截止日期", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "assignmentIdList", dataType = "List<Long>", value = "分配记录ID列表", required = true),
            @ApiImplicitParam(name = "endTime", dataType = "Date", value = "截止日期", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "更新成功")
    })
    public R<String> updateAssignmentsEndTimeByAssignmentIds(HttpServletRequest request) {
        List<Long> assignmentIdList = RequestUtil.getLongJsonArrayParameter(request, "assignmentIdList");
        Date endTime = RequestUtil.getDateParameter(request, "endTime");
        assignmentService.updateAssignmentsEndTimeByAssignmentIds(assignmentIdList, endTime);
        return R.success("更新成功");
    }


    @Action
    @ApiOperation(value = "查询单个项目所有分配记录，", httpMethod = "GET",
            notes = "根据项目ID，分配记录状态（可选）、任务类型（可选）、所属课程ID（可选）获取项目所有相关分配记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", dataType = "Long", value = "项目ID", required = true),
            @ApiImplicitParam(name = "assignmentStatus", dataType = "Integer", value = "分配记录状态"),
            @ApiImplicitParam(name = "taskType", dataType = "Integer", value = "任务类型"),
            @ApiImplicitParam(name = "courseId", dataType = "Long", value = "课程ID"),
            @ApiImplicitParam(name = "projectType", dataType = "Integer", value = "项目类型")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<List<AssignmentDto>> findAssignmentsByProjectId(HttpServletRequest request) {
        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        Integer assignmentStatus = RequestUtil.getIntegerParameter(request, "assignmentStatus");
        Integer taskType = RequestUtil.getIntegerParameter(request, "taskType");
        Long courseId = RequestUtil.getLongParameter(request, "courseId");
        Integer projectType = RequestUtil.getIntegerParameter(request, "projectType");

        List<AssignmentDto> assignmentDtoList = assignmentService.findTasksAssignments(projectId, assignmentStatus, taskType, courseId, projectType);
        return R.success(assignmentDtoList, "查询成功");
    }

    @Action
    @ApiOperation(value = "新增产线", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineName", dataType = "String", value = "产线名称", required = true),
            @ApiImplicitParam(name = "projectId", dataType = "Long", value = "项目ID", required = true),
            @ApiImplicitParam(name = "createTime", dataType = "Date", value = "创建时间", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "添加成功")
    })
    public R<String> addLine(HttpServletRequest request) {
        String lineName = RequestUtil.getStringParameter(request, "lineName");
        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        Date createTime = RequestUtil.getDateParameter(request, "createTime");
        lineService.addLine(lineName, projectId, createTime);
        return R.success("添加成功");
    }

    @Action
    @ApiOperation(value = "根据项目ID查询所有项目产线", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", dataType = "Long", value = "项目ID", required = true),
            @ApiImplicitParam(name = "projectType", dataType = "Integer", value = "项目类型", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<List<LineDto>> findLinesByProjectId(HttpServletRequest request) {
        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        Integer projectType = RequestUtil.getIntegerParameter(request, "projectType");
        List<LineDto> lines = lineService.findLinesByProjectId(projectId, projectType);
        return R.success(lines, "查询成功");
    }

    @Action
    @ApiOperation(value = "根据产线ID查询项目产线详情", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", dataType = "Long", value = "产线ID", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<LineDto> findLineByLineId(HttpServletRequest request) {
        Long lineId = RequestUtil.getLongParameter(request, "lineId");
        LineDto lineDto = lineService.findLineByLineId(lineId);
        return R.success(lineDto, "查询成功");
    }

    @Action
    @ApiOperation(value = "更新项目产线", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", dataType = "Long", value = "产线id", required = true),
            @ApiImplicitParam(name = "lineAssignments", dataType = "String", value = "产线节点列表字符串", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "更新成功")
    })
    public R<String> updateLineAssignment(HttpServletRequest request) {
        Long lineId = RequestUtil.getLongParameter(request, "lineId");
        String lineAssignments = RequestUtil.getStringParameter(request, "lineAssignments");
        List<LineAssignment> lineAssignmentList = JSONArray.parseArray(lineAssignments, LineAssignment.class);
        lineService.updateLineAssignment(lineId, lineAssignmentList);
        return R.success("更新成功");
    }

    @Action
    @ApiOperation(value = "删除项目产线与其关联的记录", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", dataType = "Long", value = "产线id", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "删除成功")
    })
    public R<String> deleteLine(HttpServletRequest request) {
        Long lineId = RequestUtil.getLongParameter(request, "lineId");
        lineService.deleteLine(lineId);
        return R.success("删除成功");
    }

    @Action
    @ApiOperation(value = "更新项目产线名称", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", dataType = "Long", value = "产线id", required = true),
            @ApiImplicitParam(name = "lineName", dataType = "String", value = "产线名称", required = true)

    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "更新成功")
    })
    public R<String> updateLineName(HttpServletRequest request) {
        Long lineId = RequestUtil.getLongParameter(request, "lineId");
        String lineName = RequestUtil.getStringParameter(request, "lineName");
        lineService.updateLineName(lineId, lineName);
        return R.success("更新成功");
    }

    @Action
    @ApiOperation(value = "复制项目产线与产线节点", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", dataType = "Long", value = "产线id", required = true),
            @ApiImplicitParam(name = "lineName", dataType = "String", value = "产线名称", required = true),
            @ApiImplicitParam(name = "projectId", dataType = "Long", value = "项目ID", required = true),
            @ApiImplicitParam(name = "createTime", dataType = "Date", value = "创建时间", required = true)

    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "复制成功")
    })
    public R<String> copyLine(HttpServletRequest request) {
        Long lineId = RequestUtil.getLongParameter(request, "lineId");
        String lineName = RequestUtil.getStringParameter(request, "lineName");
        Long projectId = RequestUtil.getLongParameter(request, "projectId");
        Date createTime = RequestUtil.getDateParameter(request, "createTime");
        lineService.copyLine(lineId, lineName, projectId, createTime);
        return R.success("复制成功");
    }

    @Action
    @ApiOperation(value = "查询单个或多个任务下的所有提交内容和提交文件", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tasksId", dataType = "List<Long>", value = "任务id列表", required = true),
            @ApiImplicitParam(name = "projectType", dataType = "Integer", value = "项目类型", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<List<SubmissionDto>> findSubmissionAndAchievementByTasksId(HttpServletRequest request) {
        List<Long> tasksId = RequestUtil.getLongJsonArrayParameter(request, "tasksId");
        Integer projectType = RequestUtil.getIntegerParameter(request, "projectType");
        List<SubmissionDto> submissions = taskService.findSubmissionAndAchievementByTasksId(tasksId, projectType);
        return R.success(submissions, "查询成功");
    }


    @Action
    @ApiOperation(value = "新增或修改评论记录", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "submissionIds", dataType = "List<Long>", value = "提交记录id列表", required = true),
            @ApiImplicitParam(name = "assignmentIds", dataType = "List<Long>", value = "分配记录id列表", required = true),
            @ApiImplicitParam(name = "score", dataType = "Double", value = "评分", required = true),
            @ApiImplicitParam(name = "comment", dataType = "String", value = "评论内容"),
            @ApiImplicitParam(name = "creatorId", dataType = "Integer", value = "评价人Id", required = true),
            @ApiImplicitParam(name = "evaluationType", dataType = "Integer", value = "评价类型", required = true),
            @ApiImplicitParam(name = "createTime", dataType = "Date", value = "创建日期", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "批阅成功")
    })
    public R<String> insertOrUpdateEvaluations(HttpServletRequest request) {
        List<Long> submissionIds = RequestUtil.getLongJsonArrayParameter(request, "submissionIds");
        Double score = RequestUtil.getDoubleParameter(request, "score");
        String comment = RequestUtil.getStringParameter(request, "comment");
        Long creatorId = RequestUtil.getLongParameter(request, "creatorId");
        Integer evaluationType = RequestUtil.getIntegerParameter(request, "evaluationType");
        Date createTime = RequestUtil.getDateParameter(request, "createTime");

        evaluationService.insertOrUpdateEvaluations(submissionIds, score, comment, creatorId, createTime, evaluationType);
        return R.success("", "批阅成功");
    }

    @Action
    @ApiOperation(value = "退回（删除）提交记录", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "submissionIds", dataType = "List<Long>", value = "提交记录id列表", required = true),
            @ApiImplicitParam(name = "assignmentIds", dataType = "List<Long>", value = "分配记录id列表", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "删除成功")
    })
    public R<String> deleteSubmissions(HttpServletRequest request) {
        List<Long> submissionIds = RequestUtil.getLongJsonArrayParameter(request, "submissionIds");
        List<Long> assignmentIds = RequestUtil.getLongJsonArrayParameter(request, "assignmentIds");


        assignmentService.updateAssignmentStatusByAssignmentId(assignmentIds, 1);
        submissionService.deleteSubmissions(submissionIds);
        return R.success("", "删除成功");
    }

    @Action
    @ApiOperation(value = "查询教师用户拥有的课程", httpMethod = "get")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", dataType = "Long", value = "用户id", required = true),
            @ApiImplicitParam(name = "courseName", dataType = "String", value = "课程名称"),
            @ApiImplicitParam(name = "currentPage", dataType = "Integer", value = "当前页数", required = true),
            @ApiImplicitParam(name = "pageSize", dataType = "Integer", value = "每页个数", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<PageBean<CourseDto>> findCoursesByUserId(HttpServletRequest request) {
        Long userId = RequestUtil.getLongParameter(request, "userId");
        String courseName = RequestUtil.getStringParameter(request, "courseName");
        Integer currentPage = RequestUtil.getIntegerParameter(request, "currentPage");
        Integer pageSize = RequestUtil.getIntegerParameter(request, "pageSize");
        PageBean<CourseDto> courseDtoPageBean = courseService.findCoursesByUserId(userId, courseName, currentPage, pageSize);
        return R.success(courseDtoPageBean, "查询成功");
    }

    @Action
    @ApiOperation(value = "查询单个课程的详情信息", httpMethod = "get")
    public R<List<Course>> findCourseDetails(HttpServletRequest request) {
        Long courseId = RequestUtil.getLongParameter(request, "courseId");
        List<Course> courseList = courseService.findCourse(courseId, null);
        return R.success(courseList, "查询成功");
    }

    @Action
    @ApiOperation(value = "查询课程的关联任务的分配记录情况", httpMethod = "get")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId", dataType = "Long", value = "课程id", required = true),
            @ApiImplicitParam(name = "evaluationType", dataType = "Integer", value = "评价类型", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<AssignmentDto> findTaskAssignmentNumberByCourseId(HttpServletRequest request) {
        Long courseId = RequestUtil.getLongParameter(request, "courseId");
        Integer evaluationType = RequestUtil.getIntegerParameter(request, "evaluationType");
        AssignmentDto assignmentDto = assignmentService.findTaskAssignmentNumberByCourseId(courseId, evaluationType);
        return R.success(assignmentDto, "查询成功");
    }

    @Action
    @ApiOperation(value = "获取课程所有班级，小组和学生", httpMethod = "get")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId", dataType = "Long", value = "课程id", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "获取成功")
    })
    public R<List<ClassDto>> findProjectClassesAndTeamsByCourseId(HttpServletRequest request) {
        Long courseId = RequestUtil.getLongParameter(request, "courseId");
        List<ClassDto> courseDtos = projectClassService.findProjectClassesAndTeamsByCourseId(courseId);
        return R.success(courseDtos, "获取成功");
    }

    @Action
    @ApiOperation(value = "新增项目班并与课程关联", httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId", dataType = "Long", value = "课程id", required = true),
            @ApiImplicitParam(name = "classNAme", dataType = "String", value = "班级名称", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "添加成功")
    })
    public R<String> addProjectClass(HttpServletRequest request) {
        Long courseId = RequestUtil.getLongParameter(request, "courseId");
        String className = RequestUtil.getStringParameter(request, "className");
        projectClassService.addProjectClass(courseId, className);
        return R.success("", "添加成功");
    }

    @Action
    @ApiOperation(value = "删除班级", httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classId", dataType = "Long", value = "班级id", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "删除成功")
    })
    public R<String> deleteProjectClass(HttpServletRequest request) {
        Long classId = RequestUtil.getLongParameter(request, "classId");
        projectClassService.deleteProjectClass(classId);
        return R.success("", "删除成功");
    }

    @Action
    @ApiOperation(value = "获取单个班级的学生", httpMethod = "get")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classId", dataType = "Long", value = "班级id", required = true),
            @ApiImplicitParam(name = "teamId", dataType = "Long", value = "小组id"),
            @ApiImplicitParam(name = "studentId", dataType = "Long", value = "学号"),
            @ApiImplicitParam(name = "haveTeam", dataType = "Integer", value = " 判断是否有小组"),
            @ApiImplicitParam(name = "userName", dataType = "String", value = "学生名称"),
            @ApiImplicitParam(name = "currentPage", dataType = "Integer", value = "当前页数", required = true),
            @ApiImplicitParam(name = "pageSize", dataType = "Integer", value = "每页总数", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<PageBean<UserDto>> findClassStudents(HttpServletRequest request) {
        Long classId = RequestUtil.getLongParameter(request, "classId");
        Long teamId = RequestUtil.getLongParameter(request, "teamId");
        Long studentId = RequestUtil.getLongParameter(request, "studentId");
        String userName = RequestUtil.getStringParameter(request, "userName");
        Integer haveTeam = RequestUtil.getIntegerParameter(request, "haveTeam");
        Integer currentPage = RequestUtil.getIntegerParameter(request, "currentPage");
        Integer pageSize = RequestUtil.getIntegerParameter(request, "pageSize");

        PageBean<UserDto> userDtoPageBean = userService.findClassStudents(classId, teamId, studentId, userName, haveTeam, currentPage, pageSize);
        return R.success(userDtoPageBean, "查询成功");
    }

    @Action
    @ApiOperation(value = "新增小组，并关联到班级", httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classId", dataType = "Long", value = "班级id", required = true),
            @ApiImplicitParam(name = "teamName", dataType = "String", value = "小组名称", required = true),

    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "添加成功")
    })
    public R<String> addTeam(HttpServletRequest request) {
        Long classId = RequestUtil.getLongParameter(request, "classId");
        String teamName = RequestUtil.getStringParameter(request, "teamName");
        teamService.addTeam(classId, teamName);

        return R.success("", "添加成功");
    }

    @Action
    @ApiOperation(value = "删除小组", httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teamId", dataType = "Long", value = "小组id", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "删除成功")
    })
    public R<String> deleteTeam(HttpServletRequest request) {
        Long teamId = RequestUtil.getLongParameter(request, "teamId");
        teamService.deleteTeam(teamId);
        return R.success("", "删除成功");
    }

    @Action
    @ApiOperation(value = "批量修改学生所在小组", httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classId", dataType = "Long", value = "班级id", required = true),
            @ApiImplicitParam(name = "teamId", dataType = "Long", value = "小组id", required = true),
            @ApiImplicitParam(name = "studentIds", dataType = "List<Long>", value = "学生id列表", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "修改成功")
    })
    public R<String> setTeamForStudents(HttpServletRequest request) {
        Long classId = RequestUtil.getLongParameter(request, "classId");
        Long teamId = RequestUtil.getLongParameter(request, "teamId");
        List<Long> studentIds = RequestUtil.getLongJsonArrayParameter(request, "studentIds");
        userService.setTeamForStudents(classId, teamId, studentIds);
        return R.success("", "修改成功");
    }

    @Action
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teamId", dataType = "Long", value = "小组id", required = true),
            @ApiImplicitParam(name = "userId", dataType = "Long", value = "用户id", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "修改成功")
    })
    public R<String> setTeamLeader(HttpServletRequest request) {
        Long teamId = RequestUtil.getLongParameter(request, "teamId");
        Long userId = RequestUtil.getLongParameter(request, "userId");
        teamService.updateTeamLeader(teamId, userId);
        return R.success("", "修改成功");
    }

    @Action
    @ApiOperation(value = "为项目班添加学生", httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classId", dataType = "Long", value = "班级id", required = true),
            @ApiImplicitParam(name = "studentIds", dataType = "List<Long>", value = "学生id列表", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "添加成功")
    })
    public R<String> addClassStudentRef(HttpServletRequest request) {
        Long classId = RequestUtil.getLongParameter(request, "classId");
        List<Long> studentIds = RequestUtil.getLongJsonArrayParameter(request, "studentIds");
        projectClassService.insertClassStudentRef(classId, studentIds);
        return R.success("", "添加成功");
    }

    @Action
    @ApiOperation(value = "为项目班删除学生", httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classId", dataType = "Long", value = "班级id", required = true),
            @ApiImplicitParam(name = "studentIds", dataType = "List<Long>", value = "学生id列表", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "删除成功")
    })
    public R<String> deleteClassStudentRef(HttpServletRequest request) {
        Long classId = RequestUtil.getLongParameter(request, "classId");
        List<Long> studentIds = RequestUtil.getLongJsonArrayParameter(request, "studentIds");
        projectClassService.deleteClassStudentRef(classId, studentIds);
        return R.success("", "删除成功");
    }

    @Action
    @ApiOperation(value = "查询工具内所有学生", httpMethod = "get")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classId", dataType = "Long", value = "班级id"),
            @ApiImplicitParam(name = "studentId", dataType = "List<Long>", value = "学生学号"),
            @ApiImplicitParam(name = "studentName", dataType = "List<Long>", value = "学生名称"),
            @ApiImplicitParam(name = "currentPage", dataType = "Integer", value = "当前页数", required = true),
            @ApiImplicitParam(name = "pageSize", dataType = "Integer", value = "每页总数", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })
    public R<PageBean<Student>> findAllStudents(HttpServletRequest request) {
        Long studentId = RequestUtil.getLongParameter(request, "studentId");
        String studentName = RequestUtil.getStringParameter(request, "studentName");
        Long classId = RequestUtil.getLongParameter(request, "classId");
        Integer currentPage = RequestUtil.getIntegerParameter(request, "currentPage");
        Integer pageSize = RequestUtil.getIntegerParameter(request, "pageSize");
        PageBean<Student> pageBean = userService.findAllStudents(classId, studentId, studentName, currentPage, pageSize);
        return R.success(pageBean, "查询成功");
    }
    @Action
    @ApiOperation(value = "注册用户", httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", dataType = "Long", value = "学号或工号"),
            @ApiImplicitParam(name = "bandId", dataType = "Long", value = "帮区ID"),
            @ApiImplicitParam(name = "password", dataType = "String", value = "密码"),
            @ApiImplicitParam(name = "email", dataType = "String", value = "邮箱"),
            @ApiImplicitParam(name = "phone", dataType = "String", value = "手机"),
            @ApiImplicitParam(name = "role", dataType = "String", value = "角色"),
            @ApiImplicitParam(name = "studentName", dataType = "String", value = "学生用户名"),
            @ApiImplicitParam(name = "teacherName", dataType = "String", value = "老师用户名")

    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "注册成功")
    })
    public R<String> addUser(HttpServletRequest request) {
        // 1. 获取基本参数
        Long userId = RequestUtil.getLongParameter(request, "userId");
        Long bandId = RequestUtil.getLongParameter(request, "bandId");
        String password = RequestUtil.getStringParameter(request, "password");
        String email = RequestUtil.getStringParameter(request, "email");
        String phone = RequestUtil.getStringParameter(request, "phone");
        String role = RequestUtil.getStringParameter(request, "role");
        String studentName = RequestUtil.getStringParameter(request, "studentName");
        String teacherName = RequestUtil.getStringParameter(request, "teacherName");
        String request1 = userService.addUser(userId,bandId,password,email,phone,role,studentName,teacherName);

        return R.success(request1,"注册成功");
    }

    @Action
    @ApiOperation(value = "用户登录", httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", dataType = "Long", value = "学号或工号"),
            @ApiImplicitParam(name = "password", dataType = "String", value = "密码"),
            @ApiImplicitParam(name = "role", dataType = "String", value = "角色"),

    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "登录成功")
    })
    public R<UserVo> findUserByPassword(HttpServletRequest request){
        Long userId = RequestUtil.getLongParameter(request, "userId");
        String password = RequestUtil.getStringParameter(request,"password");
        String role = RequestUtil.getStringParameter(request, "role");
        User Result =  userService.findUserByPassword(userId,password,role);

        UserVo dto = new UserVo();
        dto.setUserId(Result.getUserId());
        dto.setPhone(Result.getPhone());
        dto.setRole(Result.getRole());
        dto.setUsername(Result.getUserName());// 动态获取的name字段
        System.out.println(Result.getUserName());
        return R.success(dto,"登录成功");
    }
}

